<template>
  <div ref="lineChart" style="width: 50vw; height: 400px;"></div>
</template>

<script>
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts';

export default {
  name: 'MonthlyElectricityUsage',
  setup() {
    const lineChart = ref(null);

    onMounted(() => {
      initChart();
    });

    const initChart = () => {
      const chart = echarts.init(lineChart.value);
      const option = {
        title: {
          text: '月度用电量'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['用电量']
        },
        xAxis: {
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          name: '用电量',
          type: 'line',
          data: [120, 132, 101, 134, 90, 230, 210, 180, 190, 230, 210, 120] // 这里可以替换成你的实际数据
        }]
      };
      chart.setOption(option);
    };

    return {
      lineChart
    };
  }
}
</script>
